<!-- file trackingdet -->
<script> 
	
	$(function(){
		/* external function */
		
		$.fn.serializeObject = function()
		{
		   var o = {};
		   var a = this.serializeArray();
		   $.each(a, function() {
			   if (o[this.name]) {
				   if (!o[this.name].push) {
					   o[this.name] = [o[this.name]];
				   }
				   o[this.name].push(this.value || '');
			   } else {
				   o[this.name] = this.value || '';
			   }
		   });
		   return o;
		};
		
		/* declarisasi */
		
		task_trackingdet = $("#task_trackingdet");
		grid_trackingdet = $("#grid-trackingdet");
		pgrid_trackingdet = $("#pgrid-trackingdet");
		btnadd_trackingdet = $("#btn-add-trackingdet");
		btnedit_trackingdet = $("#btn-edit-trackingdet");
		btndelete_trackingdet = $("#btn-delete-trackingdet");
		btncancel_trackingdet =  $("#btn-cancel-trackingdet");
		btnsave_trackingdet = $("#btn-save-trackingdet");
		form_trackingdet = $("#form-trackingdet");
		
		field_trackingdet_id = $("#trackingdet_id");
		field_m_flowdetchecklist_id = $("#m_flowdetchecklist_id");
		field_t_tracking_id = $("#t_tracking_id");
		field_trackingdet_flag = $("#trackingdet_flag");
		
		/* method started */
		
		$( "input[type=submit],input[type=button],input[type=reset], button" ).button();
			
		/* make component */
		
		grid_trackingdet.jqGrid({ 
			ajaxGridOptions : {type:"POST"},
			serializeGridData : function(postdata) {return postdata; },
			postData : {task : 'LIST'},
            url: 'c_trackingdet',
			datatype: "json", 
			colNames:[
				'm_flowdetchecklist_id',
				't_tracking_id',
				'trackingdet_flag',
				'trackingdet_id'],
			colModel:[
				{ name: 'm_flowdetchecklist_id'  ,index: 'm_flowdetchecklist_id' , search : true},
				{ name: 't_tracking_id'  ,index: 't_tracking_id' , search : true},
				{ name: 'trackingdet_flag'  ,index: 'trackingdet_flag' , search : true},
				{ name: 'trackingdet_id'  ,index: 'trackingdet_id',key: true, hidden: true , search : false}
			],
			width: '700',
			height: 'auto',
			rowNum:10, 
			rowList:[10,20,30], 
			pager: '#pgrid-trackingdet', 
			sortname: 'trackingdet_id', 
			viewrecords: true, 
			sortorder: "desc",
			caption:"" 
		}); 
		grid_trackingdet.jqGrid('navGrid','#pgrid-trackingdet',{edit:false,add:false,del:false,search:false});
		grid_trackingdet.jqGrid('filterToolbar',{});
		
		form_trackingdet.dialog({
			autoOpen: false,
			height: "auto",
			width: "auto",
			modal: true
		});
		
		/* event */

		btnedit_trackingdet.click(function(){
			id = grid_trackingdet.jqGrid("getGridParam","selrow");
			if (id != null){
				task_trackingdet.val("UPDATE");
				dataRow = grid_trackingdet.getRowData(id);
				field_trackingdet_id.val(dataRow.trackingdet_id);
				field_m_flowdetchecklist_id.val(dataRow.m_flowdetchecklist_id);
				field_t_tracking_id.val(dataRow.t_tracking_id);
				field_trackingdet_flag.val(dataRow.trackingdet_flag);
				form_trackingdet.dialog("open");
			}
		});
		
		btndelete_trackingdet.click(function(){
			id = grid_trackingdet.jqGrid("getGridParam","selrow");
			if (id != null){
				confr = confirm("Apa Anda yakin menghapus data ini?");
				if (confr){
					$.ajax({
						type: 'POST',
						url: 'c_trackingdet',
						data: {trackingdet_id: id, task : 'DELETE'},
						success: function(response){
							if(response==1){
								grid_trackingdet.trigger('reloadGrid');
								$("#grid-trackingdet").trigger('reloadGrid');
							}
						}
					});
				}
			}
		});
		
		btnadd_trackingdet.click(function(){
			task_trackingdet.val("INSERT");
			form_trackingdet.dialog("open");
		});
		
		btncancel_trackingdet.click(function(){
			form_trackingdet.dialog("close");
		});
		
		btnsave_trackingdet.click(function(){
			data = form_trackingdet.serializeObject();
			$.ajax({
				url : "c_trackingdet",
				data : data,
				type : 'POST'
			}).done(function(response){
				grid_trackingdet.trigger('reloadGrid');
				btncancel_trackingdet.click();
			});
		});
		
	});
</script>

	<table id="grid-trackingdet" class="table table-striped table-bordered" ></table>
	<div id="pgrid-trackingdet"></div>
	
	<button id="btn-add-trackingdet">Tambah</button>
	<button id="btn-edit-trackingdet">Ubah</button>
	<button id="btn-delete-trackingdet">Hapus</button>
	
	<form id="form-trackingdet" title="trackingdet" disabled=true>
		<input type="hidden" value="INSERT" name="task" id="task_trackingdet">
	   <table>
			<tr style="display: none">
				<td align="right">trackingdet_id:</td>
				<td align="left"><input id="trackingdet_id" name="trackingdet_id" /></td>
			</tr>
			
			<tr > <td align="right">m_flowdetchecklist_id:</td> <td align="left"><input id="m_flowdetchecklist_id" name="m_flowdetchecklist_id" /></td> </tr>
			<tr > <td align="right">t_tracking_id:</td> <td align="left"><input id="t_tracking_id" name="t_tracking_id" /></td> </tr>
			<tr > <td align="right">trackingdet_flag:</td> <td align="left"><input id="trackingdet_flag" name="trackingdet_flag" /></td> </tr>
			
			<tr>
				<td align="right"></td>
				<td style="padding-top: 10px;" align="right">
					<input style="margin-right: 5px;" type="button" id="btn-save-trackingdet" value="Simpan"  />
					<input id="btn-cancel-trackingdet" type="reset" value="Batal" /></td>
			</tr>
		</table>
	</form>